package com.ktwlsoft.archivemanage.domain.business.repositoryService;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ktwlsoft.archivemanage.domain.dao.entity.Instruction;
import com.ktwlsoft.archivemanage.domain.dao.repository.InstructionMapper;
import com.ktwlsoft.archivemanage.payload.instruction.InstructionPageRequest;
import lombok.Getter;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author JokerMo
 * @version 1.0
 * @date 2019/12/12 14:08
 */
@Service
public class InstructionRepositoryService {
    @Getter
    private final InstructionMapper instructionMapper;

    public InstructionRepositoryService(InstructionMapper instructionMapper) {
        this.instructionMapper = instructionMapper;
    }
    /**
     * 指南查询分页
     * @param request
     * @return PageInfo<Instruction>
     */
    public PageInfo<Instruction> findPage(InstructionPageRequest request) {
        PageHelper.startPage(request.getPn(),request.getPageSize());
        PageInfo<Instruction> pageInfo = new PageInfo<Instruction>(instructionMapper.findPage(request));
        return pageInfo;
    }
    /**
     * 根据指南ID查询信息
     * @param id	主键
     * @return MessageManage
     */
    public Instruction getById(Long id){
        return instructionMapper.selectByPrimaryKey(id);
    }

    /**
     * 指南新增
     * @param instruction instruction
     * @return int
     */
    public int insert(Instruction instruction){
        return instructionMapper.insert(instruction);
    }

    /**
     * 指南修改
     * @param instruction instruction
     * @return int
     */
    public int update(Instruction instruction){
        return instructionMapper.updateByPrimaryKey(instruction);
    }

    /**
     * 根据指南id删除信息
     * @param id id
     * @return int
     */
    public int deleteById(Long id){
        return instructionMapper.deleteByPrimaryKey(id);
    }

    /**
     * 根据指南标题查询信息
     * @param instruction	instruction
     * @return instructionDic
     */
    public List<Instruction> getByTitle(Instruction instruction){
        return instructionMapper.getByTitle(instruction);
    }

    /**
     * 查询是否被引用及问题导航下的问题列表
     * @param belongId
     * @return
     */
    public List<Instruction> getByBelongId(Long belongId ){
        return instructionMapper.getByBelongId(belongId);
    }
}
